package at.fhj.itm;
// TODO Add JavaDoc Documentation Comments
/**
 * Gives out a Queue of numbers.
 * 
 * @author Mike Ulm
 * @author of Doc Katrin Feyrer
 * @version 1.0
 */

public class Queue {
	
  private int maxSize;

  private long[] queArray;

  private int front;

  private int rear;

  private int nItems;

  /**
   * Constructor creates an Array with the maxSize.
   * 
   * @param s defines the maxSize of the Queue
   * front sets the position in the Queue
   * nItems shows how many items are in the Queue
   * rear sets the first position
   */
  
  public Queue(int s) {
    maxSize = s;
    queArray = new long[maxSize];
    front = 0;
    rear = -1;
    nItems = 0;
  }

   // put item at end of a queue
  
  /**
   * counts 1 to rear and inserts the item at the position of rear
   * sets rear -1 if rear = maxsize-1
   * number of items in the array + 1
   * @param j passed value which is inserted
   * 
   */
  public void insert(long j) {
   if (rear == maxSize - 1){ // deal with wraparound
      rear = -1;
    }
   	if(nItems == maxSize){
       throw new IllegalStateException();
   	}
    queArray[++rear] = j; // increment rear and insert
    nItems++;
    }
   
  

  //   take item from front of queue
  /**
   * removes the first element in the array
   * @return gives back the new front element
   */
  public long remove() {
    long temp = queArray[front++]; // get value and incr front
    if (front == maxSize) // deal with wraparound
      front = 0;
    nItems--; // one less item
    return temp;
  }

  /**
   * 
   * @return gives back the front position
   */
  public long peekFront() {
    return queArray[front];
  }
  
  /**
   * 
   * @return that Array is empty
   */
  public boolean isEmpty() {
    return (nItems == 0);
  }

  /**
   * 
   * @return that Array is full
   */
  public boolean isFull() {
	 return (nItems == maxSize);
  }

  /**
   * 
   * @return gives back the number of elements
   */
  public int size() {
    return nItems;
  }

  // TODO Refactor / Delete Main Method and create JUnit test code
  
}
           
         